<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Timer - Three.js Docs</title>
	<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
	<script src="../scripts/highlight.min.js"></script>
	<link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
	<link type="text/css" rel="stylesheet" href="../styles/page.css">
</head>
<body>
	<h1 translate="no">Timer</h1>
		<section>
			<header>
				<div class="class-description"><p>This class is an alternative to <a href="Clock.html">Clock</a> with a different API design and behavior.
The goal is to avoid the conceptual flaws that became apparent in <code>Clock</code> over time.</p>
<ul>
<li><code>Timer</code> has an <code>update()</code> method that updates its internal state. That makes it possible to
call <code>getDelta()</code> and <code>getElapsed()</code> multiple times per simulation step without getting different values.</li>
<li>The class can make use of the Page Visibility API to avoid large time delta values when the app
is inactive (e.g. tab switched or browser hidden).</li>
</ul></div>
				<h2>Code Example</h2>
				<div translate="no"><pre><code class="language-js">const timer = new Timer();
timer.connect( document ); // use Page Visibility API
</code></pre></div>
			</header>
			<article>
				<div class="container-overview">
					<h2>Constructor</h2>
					<h3 class="name name-method" id="Timer" translate="no">new <a href="#Timer">Timer</a><span class="signature">()</span> </h3>
					<div class="method">
						<div class="description">
							<p>Constructs a new timer.</p>
						</div>
					</div>
				</div>
				<h2 class="subsection-title">Methods</h2>
					<h3 class="name name-method" id="connect" translate="no">.<a href="#connect">connect</a><span class="signature">( document : <span class="param-type">Document</span> )</span> </h3>
					<div class="method">
						<div class="description">
							<p>Connect the timer to the given document.Calling this method is not mandatory to
use the timer but enables the usage of the Page Visibility API to avoid large time
delta values.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>document</strong>
									</td>
									<td class="description last">
										<p>The document.</p>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
					<h3 class="name name-method" id="disconnect" translate="no">.<a href="#disconnect">disconnect</a><span class="signature">()</span> </h3>
					<div class="method">
						<div class="description">
							<p>Disconnects the timer from the DOM and also disables the usage of the Page Visibility API.</p>
						</div>
					</div>
					<h3 class="name name-method" id="dispose" translate="no">.<a href="#dispose">dispose</a><span class="signature">()</span> </h3>
					<div class="method">
						<div class="description">
							<p>Can be used to free all internal resources. Usually called when
the timer instance isn't required anymore.</p>
						</div>
					</div>
					<h3 class="name name-method" id="getDelta" translate="no">.<a href="#getDelta">getDelta</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
					<div class="method">
						<div class="description">
							<p>Returns the time delta in seconds.</p>
						</div>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> The time delta in second.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="getElapsed" translate="no">.<a href="#getElapsed">getElapsed</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
					<div class="method">
						<div class="description">
							<p>Returns the elapsed time in seconds.</p>
						</div>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> The elapsed time in second.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="getTimescale" translate="no">.<a href="#getTimescale">getTimescale</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
					<div class="method">
						<div class="description">
							<p>Returns the timescale.</p>
						</div>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> The timescale.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="reset" translate="no">.<a href="#reset">reset</a><span class="signature">()</span><span class="type-signature"> : <a href="Timer.html">Timer</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Resets the time computation for the current simulation step.</p>
						</div>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> A reference to this timer.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="setTimescale" translate="no">.<a href="#setTimescale">setTimescale</a><span class="signature">( timescale : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Timer.html">Timer</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Sets the given timescale which scale the time delta computation
in <code>update()</code>.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>timescale</strong>
									</td>
									<td class="description last">
										<p>The timescale to set.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> A reference to this timer.</dt>
						</dl>
					</div>
					<h3 class="name name-method" id="update" translate="no">.<a href="#update">update</a><span class="signature">( timestamp : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Timer.html">Timer</a></span> </h3>
					<div class="method">
						<div class="description">
							<p>Updates the internal state of the timer. This method should be called
once per simulation step and before you perform queries against the timer
(e.g. via <code>getDelta()</code>).</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>timestamp</strong>
									</td>
									<td class="description last">
										<p>The current time in milliseconds. Can be obtained
from the <code>requestAnimationFrame</code> callback argument. If not provided, the current
time will be determined with <code>performance.now</code>.</p>
									</td>
								</tr>
							</tbody>
						</table>
						<dl class="details">
							<dt class="tag-returns"><strong>Returns:</strong> A reference to this timer.</dt>
						</dl>
					</div>
				<h2 class="subsection-title">Source</h2>
				<p>
					<a href="https://github.com/mrdoob/three.js/blob/master/src/core/Timer.js" translate="no" target="_blank" rel="noopener">src/core/Timer.js</a>
				</p>
			</article>
		</section>
<script src="../scripts/linenumber.js"></script>
<script src="../scripts/page.js"></script>
</body>
</html>